<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号">
              <j-input placeholder="请输入单据编号" v-model="queryParam.billNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据类型">
              <j-dict-select-tag type="list" v-model="queryParam.erpType" dictCode="kingdee_bill_type" placeholder="请选择单据类型"/>
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
                <a-form-item label="创建日期">
                  <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
                  <span class="query-group-split-cust"></span>
                  <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
                </a-form-item>
              </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="是否成功">
              <j-dict-select-tag type="list" v-model="queryParam.isSuccess" dictCode="async_status" placeholder="请选择是否成功"/>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpKingdeeAsyncLog:add')">新增</a-button> -->
      <!--<a-button type="primary" icon="download" @click="handleExportXls('金蝶-同步日志表')" :disabled="isDisabledAuth('erpKingdeeAsyncLog:export')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpKingdeeAsyncLog:import')">导入</a-button>
      </a-upload>
      -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpKingdeeAsyncLog:delete')"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <span slot="billNo" slot-scope="text, record">
          <a @click="goDetail(record)">{{ text }}</a>
        </span>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <template v-if="record.isSuccess=='false'">
            <a-button  type="primary" size="small" @click="handleAsync(record)"  :disabled="isDisabledAuth('erpFinanceKingdeePaymentBill:edit')">同步</a-button>
          </template>
            <!-- <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="edit"
                @click="handleEdit(record)"
                :disabled="isDisabledAuth('erpKingdeeAsyncLog:edit')"
        />
        <a-divider type="vertical"/> -->
        <!-- <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a-button
                    class="ruleButton"
                    :ghost="true"
                    type="primary"
                    icon="delete"
                    :disabled="isDisabledAuth('erpKingdeeAsyncLog:delete')"/>
        </a-popconfirm> -->
        </span>

      </a-table>
    </div>

    <erp-kingdee-async-log-modal ref="modalForm" @ok="modalFormOk"></erp-kingdee-async-log-modal>
    <ErpFinanceReimbursementPenetrate  ref="reimbursementPenetrate"></ErpFinanceReimbursementPenetrate>
    <ErpFinanceLoanBillPenetrate ref="loanBillPenetrate" ></ErpFinanceLoanBillPenetrate>
    <ErpFinancePaymentBillPenetrate ref="paymentBillPenetrate" ></ErpFinancePaymentBillPenetrate>
    <ErpFinanceDepositBillPenetrate ref="projectDepositBillPenetrate" ></ErpFinanceDepositBillPenetrate>
    <ErpFinanceTraveBillPenetrate ref="traveBillPenetrate" ></ErpFinanceTraveBillPenetrate>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpKingdeeAsyncLogModal from './modules/ErpKingdeeAsyncLogModal'
  import { getAction,postAction } from '@/api/manage'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'

  export default {
    name: 'ErpKingdeeAsyncLogList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpKingdeeAsyncLogModal,
      ErpFinanceReimbursementPenetrate: () => import('@/views/scy/penetrate/ErpFinanceReimbursementPenetrate'),
      ErpFinanceLoanBillPenetrate: () => import('@/views/scy/penetrate/ErpFinanceLoanBillPenetrate'),
      ErpFinancePaymentBillPenetrate: () => import('@/views/scy/penetrate/ErpFinancePaymentBillPenetrate'),
      ErpFinanceDepositBillPenetrate: () => import('@/views/scy/penetrate/ErpFinanceDepositBillPenetrate'),
      ErpFinanceTraveBillPenetrate: () => import('@/views/scy/penetrate/ErpFinanceTraveBillPenetrate')
    },
    data () {
      return {
        description: '金蝶-同步日志表管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'单据类型',
            align:"center",
            width:200,
            dataIndex: 'erpType_dictText',
          },
          {
            title:'单据编号',
            align:"center",
            width:300,
            dataIndex: 'billNo',
            scopedSlots: { customRender: 'billNo' },
          },
          {
            title:'创建时间',
            align:"center",
            width:200,
            dataIndex: 'createTime',
          },
          {
            title:'单据id',
            align:"center",
            width:300,
            dataIndex: 'erpId',
          },
          
          {
            title:'服务',
            align:"center",
            width:300,
            dataIndex: 'service',
          },
          {
            title:'是否成功',
            align:"center",
            dataIndex: 'isSuccess_dictText',
          },
          // {
          //   title:'失败原因',
          //   align:"center",
          //   dataIndex: 'errorMsg',
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:160,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          async:"/api/erp/finance/kingdee/log/erpKingdeeAsyncLog/async",
          list: "/api/erp/finance/kingdee/log/erpKingdeeAsyncLog/list",
          delete: "/api/erp/finance/kingdee/log/erpKingdeeAsyncLog/delete",
          deleteBatch: "/api/erp/finance/kingdee/log/erpKingdeeAsyncLog/deleteBatch",
          exportXlsUrl: "/api/erp/finance/kingdee/log/erpKingdeeAsyncLog/exportXls",
          importExcelUrl: "/api/erp/finance/kingdee/log/erpKingdeeAsyncLog/importExcel",
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      // 加载穿透表单
      goDetail(record) {
        if (record.erpType == '1') {
          this.$refs.reimbursementPenetrate.initData(record.erpId);
          this.$refs.reimbursementPenetrate.visible = true;
        } else if (record.erpType == '2') {
          this.$refs.traveBillPenetrate.initData(record.erpId);
          this.$refs.traveBillPenetrate.visible = true;
        } else if (record.erpType == '3') {
          this.$refs.paymentBillPenetrate.initData(record.erpId);
          this.$refs.paymentBillPenetrate.visible = true;
        } else if(record.erpType == '4'){
          this.$refs.projectDepositBillPenetrate.initData(record.erpId);
          this.$refs.projectDepositBillPenetrate.visible = true;
        }else if(record.erpType == '5'){
          this.$refs.loanBillPenetrate.initData(record.erpId);
          this.$refs.loanBillPenetrate.visible = true;
        }
      },
      handleAsync(params){
        getAction(this.url.async,params).then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData();
            this.onClearSelected()
          }else{
            this.$message.error(res.message)
          }
        })
      },
      initDictConfig(){
      },
      handleDetail: function (record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = '详情';
        this.$refs.modalForm.disableSubmit = true;
    },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'erpType',text:'单据类型',dictCode:''})
        fieldList.push({type:'string',value:'erpId',text:'单据id',dictCode:''})
        fieldList.push({type:'string',value:'service',text:'服务',dictCode:''})
        fieldList.push({type:'string',value:'isSuccess',text:'是否成功',dictCode:''})
        fieldList.push({type:'Text',value:'errorMsg',text:'失败原因',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
